function stopit(id,state){
	var msg = state==0?"启用":"停用";
	layer.confirm("确定要"+msg+"用户吗?",{icon: 4, title:'确认信息'},function(index){
		$.post(basepath+"/subuser/cs",{id:id,status:state},function(data){
			data = eval("("+data+")");
			if(data.status==200){
				layer.msg("角色已"+msg+"！", function(){
					location.reload(true);
				});
			}
		}, "json");
	},function(index){
		layer.close(index);
	});
}

function removeOne(id){
	layer.confirm("确定要删除该角色吗?",{icon: 4, title:'确认信息'},function(index){
		layer.close(index);
		var $form=$("<form>" );
		$form.attr( "style","display:none" ).attr( "target","").attr( "method","post" )
		.attr( "action", basepath + "/subuser/del");
        var $id=$("<input>" ).attr("type" ,"hidden" ).attr("name" ,"id" ).attr("value" ,id);
		$form.append($id);
		$("body").append($form);
		$form.submit();
	},function(index){
		layer.close(index);
	});
}

function resetPwd(id){
	layer.confirm("确定要重置密码吗?",{icon: 4, title:'确认信息'},function(index){
		$.post(basepath+"/subuser/reset",{id:id,status:state},function(data){
			data = eval("("+data+")");
			if(data.status==200){
				layer.msg("密码已重置！", function(){
					layer.close(index);
				});
			}
		}, "json");
	},function(index){
		layer.close(index);
	});
}

var template = document.getElementById('script_template').innerHTML;
Mustache.parse(template);

function authrize(id){
	window.itemId = id;
	var index = layer.msg('处理中，请稍后...', {icon: 16,shade: [0.5, '#393D49'],time:0});
	$.post(basepath+"/subuser/roles",{},function(data){
		data = eval("("+data+")");
		var rendered = "";
		if(null!=data){
			rendered=Mustache.render(template, data);
			layer.close(index);
			window.layerIndex=layer.open({
			    type: 1,
			    title: '用户角色',
			    shadeClose: false,
			    shade: 0.8,
			    scrollbar:false,
			    area: ['380px', '50%'],
			    content: rendered
			}); 
		}
		
	},"json");
}
function useThis(id){
	layer.close(window.layerIndex);
	var index = layer.msg('处理中，请稍后...', {icon: 16,shade: [0.5, '#393D49'],time:0});
	$.post(basepath+"/subuser/cr",{"roleId":id,"id":window.itemId},function(data){
		layer.close(index);
		data = eval("("+data+")");
		if(null!=data&&200==data.state){
			layer.msg("操作成功", {shade: [0.5, '#393D49']},function(){
				window.location.reload(true);
			});
		}else{
			layer.msg("授予角色失败！", {shade: [0.5, '#393D49']});
		}
	});
}